//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include "DBRefRecord.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#define LENGTHTEXT 100
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
DBRefRecord::DBRefRecord (): chainID('\0'),
                             seqBegin(0),
                             seqEnd(0) {
  
  this->idCode   = new String();
  this->toString = new String();
    
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
DBRefRecord::DBRefRecord (const DBRefRecord& dbRefRecord) {
  
  this->idCode     = new String(dbRefRecord.idCode);
  this->chainID    = dbRefRecord.chainID;
  this->seqBegin   = dbRefRecord.seqBegin;
  this->seqEnd     = dbRefRecord.seqEnd;
  
  this->toString = new String();
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
DBRefRecord::DBRefRecord (const DBRefRecord* dbRefRecord) {
  
  this->idCode     = new String(dbRefRecord->idCode);
  this->chainID    = dbRefRecord->chainID;
  this->seqBegin   = dbRefRecord->seqBegin;
  this->seqEnd     = dbRefRecord->seqEnd;
  
  this->toString = new String();
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
DBRefRecord::~DBRefRecord () {
  
  if (this->idCode)   delete this->idCode;
  if (this->toString) delete this->toString;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void DBRefRecord::IdCode (String* idCode) {
  
  if (idCode) this->idCode->In(idCode);
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void DBRefRecord::ChainID (char chainID) {
  
  this->chainID = chainID;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void DBRefRecord::SeqBegin (int seqBegin) {
  
  this->seqBegin = seqBegin;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void DBRefRecord::SeqEnd (int seqEnd) {
  
  this->seqEnd = seqEnd;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* DBRefRecord::IdCode (void) {
  
  return this->idCode;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
char DBRefRecord::ChainID (void) {
  
  return this->chainID;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int DBRefRecord::SeqBegin (void) {
  
  return this->seqBegin;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int DBRefRecord::SeqEnd (void) {
  
  return this->seqEnd;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool DBRefRecord::ReadFromString (String* data) {
  
  if (!data || !data->Length()) return false;
  
  String* tmp = NULL;
  
  tmp = data->SubStr(7, 11);
  if (tmp) { this->idCode->In(tmp);            delete tmp; }
  else return false;
  
  tmp = data->SubStr(12, 13);
  if (tmp) { this->chainID = tmp->Out()[0];    delete tmp; }
  else return false;

  tmp = data->SubStr(14, 18);
  if (tmp) { this->seqBegin = atoi(tmp->Out()); delete tmp; }
  else return false;
  
  tmp = data->SubStr(20, 24);
  if (tmp) { this->seqEnd   = atoi(tmp->Out()); delete tmp; }
  else return false;
  
  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool DBRefRecord::ReadFromString (char* data) {
  
  if (!data || !strlen(data)) return false;
  
  String dataChar;
  dataChar.In(data);
  
  return this->ReadFromString(&dataChar);    

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void DBRefRecord::CleanData (void) {
  
  this->idCode->In("");
  
  this->chainID  = '\0';
  this->seqBegin = 0;
  this->seqEnd   = 0;
 
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
DBRefRecord DBRefRecord::operator= (const DBRefRecord& dbRefRecord) {
  
  this->idCode->In(dbRefRecord.idCode);
  this->chainID  = dbRefRecord.chainID;
  this->seqBegin = dbRefRecord.seqBegin;
  this->seqEnd   = dbRefRecord.seqEnd;

  return *this;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

